package com.studychen.appfxcp.commom.view;

import cn.hutool.core.convert.Convert;
import com.studychen.appfxcp.commom.model.BookkeepingViewModel;
import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.InjectViewModel;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

import java.net.URL;
import java.util.ResourceBundle;

public class BookkeepingView implements FxmlView<BookkeepingViewModel>, Initializable {

    @FXML
    private ComboBox<String> address;

    @FXML
    private Button clear;

    @FXML
    private TextField gift;

    @FXML
    private TextField giftMoney;

    @FXML
    private TextArea rmk;

    @FXML
    private Button save;

    @FXML
    private TextField uppercase;

    @FXML
    private TextField userName;

    @InjectViewModel
    private BookkeepingViewModel bookkeepingViewModel;

    @FXML
    void clearClick(ActionEvent event) {

    }

    @FXML
    void saveClick(ActionEvent event) {

    }
    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        address.setEditable(true);
        address.setStyle("-fx-font-size: 20");
        uppercase.textProperty().bind(bookkeepingViewModel.getUppercase());
        giftMoney.textProperty().addListener((o, oldValue, newValued) -> {
            if(newValued == null || "".equals(newValued)){
                bookkeepingViewModel.getUppercase().set("");
                return;
            }
            System.out.println("value:\t" + newValued);
            double money = Double.parseDouble(newValued);
            String moneyStr = Convert.digitToChinese(money);
            bookkeepingViewModel.getUppercase().set(moneyStr);
        });
    }
}
